﻿#include "AF_Lable.h"
#include "AF_Platform.h"

namespace AF
{
	Lable::Lable() :
		ATTRIB(Text)(""),
		ATTRIB(FontFile)(AF_LABLE_FONT_DEFAULT),
		ATTRIB(FontSize)(18),
		ATTRIB(FrontColour)(AF_COLOUR_BLACK),
		ATTRIB(BackColour)(AF_COLOUR_TRANSPARENT),
		m_pStyle(NULL)
	{
		m_nGType = GRAPHICS_LABEL;
	}

	Lable::Lable(const _STRING strText) :
		ATTRIB(Text)(strText),
		ATTRIB(FontFile)(AF_LABLE_FONT_DEFAULT),
		ATTRIB(FontSize)(18),
		ATTRIB(FrontColour)(AF_COLOUR_BLACK),
		ATTRIB(BackColour)(AF_COLOUR_TRANSPARENT),
		m_pStyle(NULL)
	{
		m_nGType = GRAPHICS_LABEL;
	}

	Lable::~Lable()
	{
		if(m_pStyle != NULL)
		{
			CleanStyle();
		}
	}

	void Lable::SetStyle(LableStyle& style)
	{
		if(m_pStyle != NULL)
		{
			CleanStyle();
		}

		m_pStyle = AF_NEW(LableStyle);

		m_pStyle->nLayers = AF_NEW_ARY(int*, style.nWidth);
		m_pStyle->cFronts = AF_NEW_ARY(Colour*, style.nWidth);
		for(int _nX = 0; _nX < style.nWidth; _nX++)
		{
			m_pStyle->nLayers[_nX] = AF_NEW_ARY(int, style.nHeight);
			m_pStyle->cFronts[_nX] = AF_NEW_ARY(Colour, style.nHeight);
			for(int _nY = 0; _nY < style.nHeight; _nY++)
			{
				m_pStyle->nLayers[_nX][_nY] = style.nLayers[_nX][_nY];
				m_pStyle->cFronts[_nX][_nY] = style.cFronts[_nX][_nY];
			}
		}

		m_pStyle->nWidth = style.nWidth;
		m_pStyle->nHeight = style.nHeight;
	}

	LableStyle* Lable::GetStyle()
	{
		return m_pStyle;
	}

	void Lable::CleanStyle()
	{
		AF_CHECK(m_pStyle != NULL);

		for(int _nX = 0; _nX < m_pStyle->nWidth; _nX++)
		{
			AF_DELETE(m_pStyle->nLayers[_nX]);
			AF_DELETE(m_pStyle->cFronts[_nX]);
		}
		AF_DELETE(m_pStyle->nLayers);
		AF_DELETE(m_pStyle->cFronts);

		AF_DELETE(m_pStyle);
	}
}

